/*
 * Copyright(c) 2018 优居科技 All rights reserved.
 * distributed with this file and available online at
 * http://www.yjyz.com/
 */
package com.zb.api.business.controller;

import com.zb.api.business.dto.PosWaresDto;
import com.zb.api.business.service.IPosWaresService;
import com.zb.api.common.models.Page;
import com.zb.api.common.models.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
* 材料表
 *
 * @author cwp
 * @version v1.0
 * @CreationTime: - 2022-02-08 14:19:31
 * @Description:
 */
@Api("材料表")
@RestController
@Slf4j
@RequestMapping("/PosWares")
public class PosWaresController {

    @Resource
    private IPosWaresService posWaresService;

    @GetMapping("/lists")
    @ApiOperation(value="获取分页材料表数据", nickname = "posWaresList")
    public Result<Page<PosWaresDto>> posWaresList(@RequestParam(defaultValue = "1") @ApiParam(name = "pageNo", value = "当前页") int pageNo,
                                                  @RequestParam(defaultValue = "10") @ApiParam(name = "pageSize", value = "每页记录数") int pageSize,
                                                  PosWaresDto posWaresDto){
        return new Result("查询成功", posWaresService.getPosWaresList(pageNo, pageSize, posWaresDto));
    }

    @GetMapping("/{id}")
    @ApiOperation(value="获取材料表", nickname = "getPosWares")
    public Result<PosWaresDto> getPosWares(@PathVariable("id") String id) {
        return new Result("查询成功", posWaresService.get(id));
    }

    @PutMapping
    @ApiOperation(value="更新材料表", nickname = "updatePosWares")
    public Result<Integer> updatePosWares(@RequestBody PosWaresDto posWaresDto) {
        return new Result("修改成功", posWaresService.update(posWaresDto));
    }

    @PostMapping("/insertPosWares")
    @ApiOperation(value="插入材料表", nickname = "insertPosWares")
    public Result<Integer> insertPosWares(@RequestBody PosWaresDto posWaresDto) {
        return new Result("录入成功", posWaresService.insert(posWaresDto));
    }

    @PostMapping("/delPosWares")
    @ApiOperation(value="移除材料", nickname = "insertPosWares")
    public Result<Integer> delPosWares(@RequestBody PosWaresDto posWaresDto) throws IllegalAccessException {
        return new Result("操作成功", posWaresService.delPosWares(posWaresDto));
    }

    @PostMapping("/getList")
    @ApiOperation(value="查询材料列表", nickname = "getList")
    public Result<Page<PosWaresDto>> getList(@RequestBody PosWaresDto posWaresDto) throws IllegalAccessException {
        return new Result("查询成功", posWaresService.getList(posWaresDto));
    }

}
